package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.component.RoundCornerImageView;
import com.pdsu.graduation_design.domain.Commodity;
import com.squareup.picasso.Picasso;

import java.util.List;

public class MainActivityListViewAdapter extends BaseAdapter {

    /**
     * 数据改为网络数据
     * @return
     */
    private List<Commodity> commodities;
    private Context context;


    public MainActivityListViewAdapter( Context context,List<Commodity> commodities) {
        this.commodities = commodities;
        this.context = context;
    }

//    private int[] images={R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber,R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber};
//    private String[] goodsName={"potato","tomato","cucumber","potato","tomato","cucumber"};

    private ImageView activity_main_listview_item_image;
    private TextView activity_main_listview_item_title ,price,username_tv,message_tv;


    /**
     *
     * 添加删除按钮
     */
    private Button add_btn;
    private Button delete_btn;

    public MainActivityListViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return commodities.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(context,R.layout.activity_main_grid_view_item_detail_item,null);
        activity_main_listview_item_image=view.findViewById(R.id.activity_main_listview_item_image);
        activity_main_listview_item_title=view.findViewById(R.id.activity_main_listview_item_title);
        price=view.findViewById(R.id.activity_main_listview_item_price);
        username_tv = view.findViewById(R.id.activity_main_listview_item_username_tv);
        message_tv=view.findViewById(R.id.activity_main_listview_item_message);

        Picasso.with(context).load(commodities.get(position).getImage()).into(activity_main_listview_item_image);
        activity_main_listview_item_title.setText(commodities.get(position).getCname());
        username_tv.setText(commodities.get(position).getUsername());
        price.setText(commodities.get(position).getPrice().toString());
        message_tv.setText(commodities.get(position).getCmessage());


        return view;
    }
}
